package presentation.controller.adminServlet;

import presentation.controller.adminServlet.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import data.DAO.CommentDAO;
import model.entity.Comment;

@WebServlet(name = "CommentManagementServlet", urlPatterns = {"/CommentManagementServlet"})
public class CommentManagementServlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        if("GetAllComment".equals(request.getParameter("view"))){
            List list = CommentDAO.getInstance().getAllComment();
            request.setAttribute("list", list);
            RequestDispatcher dispatcher = request.getRequestDispatcher("CommentManagement.jsp");
            dispatcher.forward(request, response);
        }
        
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        Comment comment = (Comment) request.getAttribute("Comment");
//        if (request.getParameter("submit").equals("DeleteComment")) {
//            CommentDAO.getInstance().deleteComment(comment.getCommentID());
//        }
        if(request.getParameter("view").equals("GetAllComment")){
            List list = CommentDAO.getInstance().getAllComment();
            request.setAttribute("list", list);
            RequestDispatcher dispatcher = request.getRequestDispatcher("CommentManagement.jsp");
            dispatcher.forward(request, response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
//        Comment comment = (Comment) request.getAttribute("Comment");
//        if (request.getParameter("submit").equals("DeleteComment")) {
//            CommentDAO.getInstance().deleteComment(comment.getCommentID());
//        }
//        if(request.getParameter("view").equals("GetAllComment")){
//            List<Comment> list = CommentDAO.getInstance().getAllComment();
//            request.setAttribute("list", list);
//            RequestDispatcher dispatcher = request.getRequestDispatcher("CommentManagement.jsp");
//            dispatcher.forward(request, response);
//        }
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
